home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JList;
- import com.sun.java.swing.ListCellRenderer;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.border.Border;
- import com.sun.java.swing.border.EmptyBorder;
- import java.awt.Component;
- import java.io.Serializable;
-
- public class BasicListCellRenderer extends JLabel implements ListCellRenderer, Serializable {
- protected static Border noFocusBorder;
-
- public BasicListCellRenderer() {
- noFocusBorder = new EmptyBorder(1, 1, 1, 1);
- ((JComponent)this).setOpaque(true);
- ((JComponent)this).setBorder(noFocusBorder);
- }
-
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- if (isSelected) {
- ((Component)this).setBackground(list.getSelectionBackground());
- ((Component)this).setForeground(list.getSelectionForeground());
- } else {
- ((Component)this).setBackground(((Component)list).getBackground());
- ((Component)this).setForeground(((Component)list).getForeground());
- }
-
- if (value instanceof Icon) {
- ((JLabel)this).setIcon((Icon)value);
- } else {
- ((JLabel)this).setText(value == null ? "" : value.toString());
- }
-
- ((JLabel)this).setFont(((Component)list).getFont());
- ((JComponent)this).setBorder(cellHasFocus ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
- return this;
- }
- }
-